﻿using System.Data.Entity.ModelConfiguration;
using yiCommerce.Core.Domain.Orders;

namespace yiCommerce.Data.Mapping.Orders
{
    public class OrderMapping: EntityTypeConfiguration<Order>
    {
        public OrderMapping()
        {
            this.ToTable("Order");
            this.HasKey(o => o.Id);

            this.Property(o => o.OrderShippingPrice).HasPrecision(18, 4);

            this.Property(o => o.OrderTotal).HasPrecision(18, 4);
            this.Property(o => o.RefundedAmount).HasPrecision(18, 4);

          
            this.Ignore(o => o.OrderStatus);
            this.Ignore(o => o.PaymentStatus);
            this.Ignore(o => o.ShippingStatus);
        
            
            this.HasRequired(o => o.Customer)
                .WithMany(c => c.Orders)
                .HasForeignKey(o => o.CustomerId);


            this.HasRequired(o => o.Shop)
                  .WithMany(c => c.Orders)
            .HasForeignKey(o => o.ShopId).WillCascadeOnDelete(false); 


            this.HasOptional(o => o.ShippingAddress)
                .WithMany()
                .HasForeignKey(o => o.ShippingAddressId)
                .WillCascadeOnDelete(false);
        }
    }
}